﻿//_______________________________________________________________________________________________________________________
// Copy Right (c) 2010, 2011 SapiensIT Consulting GmbH, all rights reserved
//_______________________________________________________________________________________________________________________
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT
// NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//_______________________________________________________________________________________________________________________
// PROJECT:     sapiens.at.SharePoint (SharePoint 2010/V4)
//_______________________________________________________________________________________________________________________
// VERSION:     2.0
//_______________________________________________________________________________________________________________________
// DESCRIPTION: 
//_______________________________________________________________________________________________________________________
// LICENSE:     Different licens Types apply to different file types:
//               - Source code files are governed by the MICROSOFT PUBLIC LICENSE (Ms-PL)
//               - Binary files are governed by MSDN CODE GALLERY BINARY LICENSE
//               - Documentation files are governed by CREATIVE COMMONS ATTRIBUTION 3.0 LICENSE
//
//               The licenses can be found at the projects source location.
//               If you do not agree, don't use it!
// 
//_______________________________________________________________________________________________________________________
// Start SharePoint Branding, visit http://www.cliggin.com! Visit us on http://www.sapiens.at! Tell your friends! 
//_______________________________________________________________________________________________________________________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Sapiens.at.SharePoint.Entities;
using Sapiens.at.SharePoint.Repositories;

namespace Sapiens.at.SharePoint.Receiver
{
    /// <summary>
    /// The arguments that are passed to the event receiver of the <see cref="BaseItemReceiver"/>.
    /// </summary>
    public class ItemEventArgs
    {
        IEntity _entity;
        /// <summary>
        /// Gets the entity for this event.
        /// </summary>
        public IEntity Entity
        {
            get { return _entity; }
        }

        IListRepository _repository;
        /// <summary>
        /// Gets the repository for the list of the event.
        /// </summary>
        public IListRepository Repository
        {
            get
            {
                if (_repository == null)
                {
                    _repository = new ListRepository(Entity.List.ID, Web);
                }
                return _repository;
            }
        }

        Dictionary<string, object> _changedValues;
        /// <summary>
        /// Gets a dictionary representing the values that changed.
        /// </summary>
        public Dictionary<string, object> ChangedValues
        {
            get { return _changedValues; }
        }

        SPWeb _web;
        /// <summary>
        /// Gets the current SPWeb. DO NOT DISPOSE!
        /// </summary>
        public SPWeb Web
        {
            get { return _web; }
        }

        /// <summary>
        /// Gets or sets whether an update should be done after all events are handled.
        /// </summary>
        public bool DoUpdate { get; set; }

        /// <summary>
        /// Gets or sets whether the event receiver should fire additional events on updating other items.
        /// </summary>
        public bool EnableEvents { get; set; }

        /// <summary>
        /// Gets or sets whether the processing cancels after this event.
        /// </summary>
        public bool Cancel { get; set; }

        /// <summary>
        /// Gets or sets whether the processing cancels after this event.
        /// </summary>
        public string CancelErrorMessage { get; set; }

        SPItemEventProperties _eventProperties;
        /// <summary>
        /// Gets the current event properties
        /// </summary>
        public SPItemEventProperties EventProperties
        {
            get { return _eventProperties; }
        }

        /// <summary>
        /// Instantiates new aruments for an item event.
        /// </summary>
        /// <param name="entity">The entity of the event</param>
        /// <param name="changedValues">The values that got changed during the event</param>
        /// <param name="web">The web of the event</param>
        /// <param name="eventProperties">The event properties itself</param>
        public ItemEventArgs(IEntity entity, Dictionary<string, object> changedValues, SPWeb web, SPItemEventProperties eventProperties)
        {
            _web = web;
            _entity = entity;
            _changedValues = changedValues;
            _eventProperties = eventProperties;
            DoUpdate = true;
        }
    }
}
